
$(document).ready(function(){

/* CSS FÜR SOCIAL MEDIA */

//$('#iframefacebook').contents().find('.pluginButtonLabel').css({
//  "font-size":"9px !important"
//});


/*
$(function() {
  $('input[name=telephone]').val('bitte wie folgt ausfüllen: Vorwahl - Telefonnummer');
  
  $('input[name=telephone]').click(
    function() {
      $(this).val("");
    }
  ); 
  
  $('input[name=telephone]').blur(
    function() { 
      $(this).val("bitte wie folgt ausfüllen: Vorwahl - Telefonnummer");
    }
  ); 
});
*/

/* BOX SERVICE */

$(function() {
  if ($('.box_service').length > 0) {
		topbox = $('.box_service').offset().top;
		// console.log('topbox = ' + topbox);
	}
});

window.onscroll = function() {
  if (typeof topbox !== 'undefined')
  {
    //var top = $('.box_service').offset().top;
    var scrollposition = $(window).scrollTop();
  
    // console.log(topbox);
    if (scrollposition > topbox - 15) {
      $('.box_service').css({
        "position":"fixed",
        "top":"15px" 
      }); 
    } else {
      $('.box_service').css({
        "position":"relative",
        "top":"0" 
      });
    };
  }
};


/* ######### Browserweichen ############# */

  if (!!navigator.userAgent.match(/Trident\/7\./)) {
    $('#signin_menu').css('width','220px');
  }
  if ($.browser.msie) {
   /*$('#signin_menu input[type="text"]').css('','');
   $('#signin_menu input[type="password"]').css('',''); 
   $('#signin_menu').css('width','220px;')             */
  }
  if ($.browser.webkit) {     
  }
  if ($.browser.safari) {   
  }
  if ($.browser.opera) {
  }
  if ($.browser.mozilla) {    
  }

/* ######### DropDown ############# */

  $('div.itdotmedia_main_navigation ul.level1 li.has_sub').hover(

    function(){
    
      var container = $(this).children('div.dropdown');
      var arrow = $(this).children('div.naviarrow');
      var overlay = $('.navigation_layer');
      container.show();
      arrow.show();
      overlay.show();
      container.position({
        my: "left top",
        at: "left bottom",
        of: $('div.itdotmedia_main_navigation')
      });
    },
    function(){
      var container = $(this).children('div.dropdown');
      var arrow = $(this).children('div.naviarrow');
      var overlay = $('.navigation_layer');
      container.hide();
      arrow.hide();
      overlay.hide();
    }
  );
  
  $('div.itdotmedia_main_navigation ul.level1 li.has_sub .img-sub').hover(
    
    function(){
       $('div.itdotmedia_main_navigation ul.level1 li.has_sub .img-sub').css('opacity','0.5');
       
       $(this).css('opacity','1');
    },
    function(){
      $('div.itdotmedia_main_navigation ul.level1 li.has_sub .img-sub').css('opacity','1')
    }
    
  );
  
  /* WARENKORB */
  
  $('.cartnotempty').hover(
    function(){
      var overlay = $('.navigation_layer');
      overlay.show();
    },
    function(){
      var overlay = $('.navigation_layer');
      overlay.hide();
    }
  );
  
  /* WARENKORB ENDE */
  
/* ######### Gallery ########## */  
  
  $('.container_popup_layer .thmb img').hover(
    
    function(){
       $('.container_popup_layer .thmb img').css('opacity','0.75');
       
       $(this).css('opacity','1');
    },
    function(){
      $('.container_popup_layer .thmb img').css('opacity','1')
    }
    
  );
  
  

});

/* Style für Radiobuttons, Checkboxen und Listen */
/* http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ */

var checkboxHeight = "19";
var radioHeight = "19";
var selectWidth = "190";

/* No need to change anything after this */

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className.indexOf("styled") > -1) {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className.indexOf("styled") > -1) {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;

			//fire event - edited DM edv-mueller.com
			$(element).change();
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
			//fire event - edited DM edv-mueller.com
			$(element).change();
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className.indexOf("styled") > -1) {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className.indexOf("styled") > -1) {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className.indexOf("styled") > -1) {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className.indexOf("styled") > -1) {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
		return true;
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
//				document.getElementById("select" + this.name)
			}
		}
	}
}
window.onload = Custom.init;